home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume15 / gbench / part02 < prev    next >
Encoding:
Internet Message Format  |  1988-06-12  |  30.6 KB

  1. Subject:  v15i069:  Graphics benchmark toolkit for X, Part02/02
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: Craig Dunwoody <dunwoody@lurch.stanford.edu>
  7. Posting-number: Volume 15, Issue 69
  8. Archive-name: gbench/part02
  9.  
  10. #! /bin/sh
  11. # This is a shell archive.  Remove anything before this line, then unpack
  12. # it by saving it into a file and typing "sh file".  To overwrite existing
  13. # files, type "sh file -c".  You can also feed this as standard input via
  14. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  15. # will see the following message at the end:
  16. #        "End of archive 2 (of 2)."
  17. # Contents:  gbench.man ops.c
  18. # Wrapped by rsalz@fig.bbn.com on Mon Jun 13 15:32:52 1988
  19. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  20. if test -f 'gbench.man' -a "${1}" != "-c" ; then 
  21.   echo shar: Will not clobber existing file \"'gbench.man'\"
  22. else
  23. echo shar: Extracting \"'gbench.man'\" \(17835 characters\)
  24. sed "s/^X//" >'gbench.man' <<'END_OF_FILE'
  25. X.TH GBENCH 1 "1 March 1988" "InterViews" "InterViews Reference Manual"
  26. X.SH NAME
  27. Xgbench \- graphics benchmark
  28. X.SH SYNOPSIS
  29. X\fBgbench\fP [-\fIcommandname\fP [\fIparameters\fP]]*
  30. X.SH DESCRIPTION
  31. X\fIgbench\fP is a graphics benchmark tool.  It currently supports 2D
  32. Ximmediate-mode graphics and runs on top of the X Window System, both Version 10
  33. Xand Version 11.  It is written in C and it directly calls the low-level window
  34. Xsystem client library; no toolkit is used.
  35. X.PP
  36. XWhen \fIgbench\fP starts, it creates a window and begins processing
  37. Xcommands.  You may supply any number of commands as arguments to the
  38. Xprogram.  Once these commands have been processed, commands are read from
  39. Xstandard input, one per line.  Each command directs \fIgbench\fP to
  40. Xrepeatedly perform a particular drawing operation.  \fIgbench\fP copies the
  41. Xcommand to the outfile (default:  standard output), executes the command,
  42. Xand prints on the outfile the host load average, the time for each
  43. Xiteration, and the number of iterations per second.
  44. X.PP
  45. XAll times are measured in real (wall-clock) time.  You should establish that
  46. Xthe host(s) and network (if used) are unloaded so that valid numbers may be
  47. Xobtained.
  48. X.PP
  49. XWhen \fIgbench\fP performs a sequence of drawing operations, each operation
  50. Xis shifted by one pixel in x and y from the previous one.  This shifting
  51. Xgoes back and forth over a user-definable range (default: 32 pixels), the
  52. Xintent being to average out the effects of pixel alignment in the frame
  53. Xbuffer.  Pixel alignment can affect the performance of many graphics
  54. Xsystems, both low-end memory-mapped frame buffers and high-end systems with
  55. Xinterleaved pixel processors.
  56. X.PP
  57. XYou can use \fIgbench\fP either interactively, by typing
  58. Xcommands and viewing the results immediately, or in batch mode,
  59. Xwith standard input redirected to a script file and output
  60. Xredirected to a log file.  To avoid cluttering up the log when
  61. Xoutput is redirected to a file, certain outputs that are only useful in
  62. Xinteractive use are directed to standard error rather than the outfile.
  63. X.PP
  64. X\fBCommands\fP
  65. X.PP
  66. XEach command consists of a command name followed by zero or more optional
  67. Xparameters separated by white space.  You may abbreviate command names to
  68. Xtheir smallest unique prefix.  Ambiguous command names are resolved to the
  69. Xfirst matching name.  Any command name may be prefixed with the @ character,
  70. Xwhich forces all output from the command to standard error rather than
  71. Xthe outfile.  This is useful for preventing selected commands from
  72. Xgoing into a log file.
  73. X.PP
  74. XThe optional parameters consist of zero or more positional parameters of the
  75. Xform \fIvalue\fP, followed by zero or more keyword parameters of the form
  76. X\fIname\fP=\fIvalue\fP.  Each positional parameter has a name and may be
  77. Xspecified in keyword form as well.  The positional form is more convenient
  78. Xfor interactive input, while the keyword form is more suited for creating
  79. Xself-documenting script files.
  80. X.PP
  81. XTo provide values for parameters that are not specified in a command,
  82. X\fIgbench\fP maintains a set of global defaults that may be displayed and
  83. Xchanged using the 'default' command.  Each default value has a name and may
  84. Xbe overridden in a command using a \fIname\fP=\fIvalue\fP parameter.
  85. XThe names of all global default values are given below.  The
  86. X'init' command restores all global defaults to their initial values.
  87. X.PP
  88. XThe first positional parameter for each command is \fIopts\fP.  It is a
  89. Xcomma-separated list of option flags, the meanings of which are described
  90. Xbelow.  Option flags may be supplied in any order.  If the \fIopts\fP
  91. Xparameter is given in positional form, the global default option list is
  92. Xprepended to the given list; if it is given in keyword form, the given
  93. Xlist is used as is, overriding the global default option list.
  94. X.PP
  95. XThe commands are:
  96. X.TP
  97. Xarc [\fIopts\fP] [\fIsize\fP] [\fIaspect\fP] [\fIangle\fP] [\fIlwidth\fP] [\fIname\fP=\fIvalue\fP]*
  98. XDraws an arc of an ellipse.  The ellipse is drawn in a bounding box with an
  99. Xarea of \fIsize\fP squared pixels and a height/width ratio of \fIaspect\fP.
  100. XThe default value of \fIaspect\fP is 1.0, yielding a circular arc.
  101. XThe arc begins at the 3 o'clock position and continues counterclockwise for
  102. X\fIangle\fP degrees.  This command works only in the X11 version.
  103. X.TP
  104. Xblit [\fIopts\fP] [\fIsize\fP] [\fIoffset\fP] [\fIname\fP=\fIvalue\fP]*
  105. XCopies a square area of the window, \fIsize\fP pixels on a side, to
  106. Xan area offset by \fIoffset\fP*\fIsize\fP pixels.  The default value for
  107. X\fIoffset\fP is 0.5.
  108. X.TP
  109. Xmap [\fIopts\fP] [\fIsize\fP] [\fInwin\fP] [\fIname\fP=\fIvalue\fP]*
  110. XMaps and then unmaps \fInwin\fP square subwindows, each \fIsize\fP
  111. Xpixels on a side.
  112. X.TP
  113. Xnop [\fIopts\fP] [\fIname\fP=\fIvalue\fP]*
  114. XPerforms a window server no-op.  This command works only in the X11 version.
  115. X.TP
  116. Xpoint [\fIopts\fP]
  117. XDraws a point.  This command works only in the X11 version.
  118. X.TP
  119. Xpoly [\fIopts\fP] [\fIsize\fP] [\fInvert\fP] [\fIlwidth\fP] [\fIname\fP=\fIvalue\fP]*
  120. XDraws a polygon with the specified number of vertices and linewidth,
  121. Xinscribed in a circle of radius \fIsize\fP pixels.
  122. X.TP
  123. Xrect [\fIopts\fP] [\fIsize\fP] [\fIlwidth\fP] [\fIname\fP=\fIvalue\fP]*
  124. XDraws an axis-aligned square, \fIsize\fP pixels on a side, with the specified
  125. Xlinewidth.
  126. X.TP
  127. Xtext [\fIopts\fP] [\fInchar\fP] [\fIptsize\fP] [\fIname\fP=\fIvalue\fP]*
  128. XDraws a text string with the specified number of characters, at the
  129. Xspecified point size.  The closest available point size is chosen.
  130. X.TP
  131. Xvec [\fIopts\fP] [\fIsize\fP] [\fIangle\fP] [\fIlwidth\fP] [\fIname\fP=\fIvalue\fP]*
  132. XDraws a vector \fIsize\fP pixels long, with the specified linewidth and
  133. Xangle (given in degrees counterclockwise from the 3 o'clock position).
  134. X.TP
  135. Xconfig
  136. XPrints the host name, display name, window system version, current time,
  137. Xand tag (see below) on the outfile.
  138. X.TP
  139. Xdefaults [\fIname\fP=\fIvalue\fP]*
  140. XPrints the defaults on standard error and optionally changes them.  The
  141. Xnames of the default values are given below.
  142. X.TP
  143. Xhelp
  144. XPrints a help message on the outfile listing the available commands and
  145. Xoption flags.
  146. X.TP
  147. Xinit
  148. XRestores all defaults to their initial value, and prints the updated
  149. Xset of values on standard error.
  150. X.TP
  151. Xscript [\fIfilename\fP]
  152. XRun the given script file, which may itself use the 'script' command.  If
  153. Xno file is given, the built-in script is run.
  154. X.TP
  155. Xquit
  156. XExits \fIgbench\fP.
  157. X.TP
  158. X!
  159. XRepeat:  Re-issue the previous drawing command, with parameters defaulting
  160. Xto the values used when that command was executed, rather than to the global
  161. Xdefault values.  Positional and keyword parameters for the command may be
  162. Xgiven in the normal manner to override the defaults.  As usual, if the
  163. X\fIopts\fP parameter is given in positional form, the default option
  164. Xlist is prepended to the given list, whereas if it is given in keyword
  165. Xform, the given list overrides the default option list.
  166. X.TP
  167. X#
  168. XComment:  causes \fIgbench\fP to write the rest of the command to
  169. Xthe outfile. This is useful for putting comments in script files.  After
  170. Xechoing and executing each command, \fIgbench\fP writes a result line
  171. Xto the outfile.  Since each result line begins with the comment
  172. Xcharacter, \fIgbench\fP output logs are also valid \fIgbench\fP input
  173. Xscripts.  You can run a log through \fIgbench\fP several times using
  174. Xdifferent hardware configurations.  In the resulting log, each command
  175. Xwill be followed by a series of result lines, one for each configuration.
  176. X.PP
  177. X\fBOptions\fP
  178. X.PP
  179. XThe option flags are as follows:
  180. X.TP 8
  181. Xac
  182. XAlternate the drawing color between black and white on each drawing
  183. Xoperation.  This measures the effect of changing one element of the
  184. Xgraphics state for each drawing operation.
  185. X.TP
  186. Xaf
  187. XUse a separate text item, with its own font identifier, for each character
  188. Xin the 'text' command.  The same font is used for all characters.  This
  189. Xoption works only in the X11 version.
  190. X.TP
  191. Xag
  192. XAlternate the graphics context on each drawing operation.  The two graphics
  193. Xcontexts used are identical except that one draws with white and the other
  194. Xdraws with black.  The ac and ag flags can be used to compare the cost of
  195. Xchanging one element of the graphics state with the cost of swapping the
  196. Xentire graphics state.
  197. X.TP
  198. Xaw
  199. XAlternate windows on each drawing operation.  This flag makes it possible
  200. Xto measure the performance impact of context-switching between windows.
  201. XIt is important to keep this overhead low in order to support applications
  202. Xthat do real-time drawing in multiple windows simultaneously.
  203. X.TP
  204. Xd
  205. XDragging.  You are prompted to move the mouse around in the window while
  206. Xholding down a mouse button.  Every time a mouse motion event is received,
  207. X\fIgbench\fP draws a background-color rectangle to erase the results of the
  208. Xprevious drawing operations, then performs one drawing iteration.  This
  209. Xoption allows you to measure the frame rate that the system can achieve
  210. Xduring interactive animation.
  211. X.TP
  212. Xf
  213. XFill the arc, polygon, or rectangle with a solid color.
  214. X.TP
  215. Xi
  216. XDraw by inverting pixel values rather than painting.  This measures
  217. Xthe additional cost of reading pixels from the frame buffer before writing.
  218. X.TP
  219. Xm
  220. XMonitor for profiling.  Profiling information is accumulated while this
  221. Xcommand is executing.  If \fIgbench\fP has been compiled and linked for
  222. X\fIgprof\fP profiling, this information is written to the file "gmon.out"
  223. Xin the current directory when \fIgbench\fP exits.
  224. X.TP
  225. Xn
  226. XNo options.  If you choose no options and you supply \fIopt\fP as
  227. Xa positional parameter, you must use the n flag as a placeholder.
  228. X.TP
  229. Xo
  230. XOverlap the object being drawn with a very small window.  The overlapping
  231. Xwindow is made small to avoid a significant change in the number of pixels
  232. Xdrawn.  This measures the cost of clipping.
  233. X.TP
  234. Xos
  235. XUse an offscreen pixel map identical in size and depth to the graphics window
  236. Xas the source for blits.  This option works only in the X11 version.
  237. X.TP
  238. Xod
  239. XUse an offscreen pixel map identical in size and depth to the graphics window
  240. Xas the destination for drawing operations.  After the command has been
  241. Xcompleted and timed, the contents of the offscreen pixel map are blitted
  242. Xinto the graphics window so correct drawing can be verified.  This option
  243. Xworks only in the X11 version.  Together, the os and od options allow you
  244. Xto measure the performance impact of offscreen rendering and the cost
  245. Xof moving pixels to and from offscreen memory.
  246. X.TP
  247. Xp
  248. XPolling.  Used in conjunction with the d flag, this flag specifies that
  249. X\fIgbench\fP should loop continuously, reading the mouse position and
  250. Xperforming a drawing iteration, rather than responding to mouse motion
  251. Xevents.  This measures the performance difference between polling and
  252. Xevent-driven input.
  253. X.TP
  254. Xps
  255. XPolygon self-intersecting.  Draw a polygon with the same vertices and number
  256. Xof edges as usual, but self-intersecting.  \fInvert\fP will be rounded up
  257. Xto an odd number if necessary.
  258. X.TP
  259. Xpw
  260. XFill polygons using the non-zero winding number rule rather than the
  261. Xdefault even-odd rule.  This option works only in the X11 version.
  262. X.TP
  263. Xr
  264. XReset defaults.  Copy the set of parameters used in this command to the
  265. Xset of global defaults.
  266. X.TP
  267. Xs
  268. XUse a stipple pattern when drawing.  The stipple pattern is a bitmap that is
  269. Xtessellated over the drawing area.  When a drawing operation is performed,
  270. Xthe only pixels that are actually drawn are those inside the shape being
  271. Xdrawn that correspond to a '1' in the stipple pattern.  These pixels are
  272. Xdrawn in the foreground color.  Stippling is fully supported only in the X11
  273. Xversion.
  274. X.TP
  275. Xt
  276. XUse a tile when drawing.  The tile is a pixel map that is tessellated over
  277. Xthe drawing area.  When a drawing operation is performed, the pixel value
  278. Xfor each pixel inside the shape being drawn is obtained from the tile.
  279. XWhen the s and t flags are used simultaneously, the stipple pattern is used
  280. Xas a tile, with '0' pixels in the stipple pattern selecting the background
  281. Xcolor and '1' pixels selecting the foreground color.  This combination works
  282. Xonly in the X11 version.
  283. X.TP
  284. Xu
  285. XUnbatched.  Normally the window system client library will batch many
  286. Xrequests into a single message to the window server in order to minimize
  287. Xcommunication overhead.  This option causes the client's request buffer
  288. Xto be flushed after each operation, thereby preventing batching.  This
  289. Xmakes it possible to directly measure the performance benefit of batching.
  290. X.PP
  291. X\fBGlobal defaults\fP
  292. X.PP
  293. XThe following global defaults may be displayed and set using the 'defaults'
  294. Xcommand:
  295. X.TP 8
  296. Xtimegoal
  297. XWhen a command is executed, \fIgbench\fP should repeat the drawing
  298. Xoperation under test enough times to get an accurate measurement of its
  299. Xcost, but not so many times that the command takes an inordinate amount of
  300. Xtime to execute.  \fIgbench\fP allows you to specify a time goal, which
  301. Xis the number of seconds that each command should take to execute (default:
  302. X1).  \fIgbench\fP performs as many iterations as are necessary to reach
  303. Xthis goal.  Setting timegoal to 0 forces \fIgbench\fP to execute a
  304. Xsingle iteration.
  305. X.TP
  306. Xcount
  307. XSpecifies the number of times to perform the primitive drawing operation
  308. Xon \fIeach\fP iteration.  This defines the unit of work being measured.
  309. XFor example, to measure the time it takes to draw a 1000-polygon object,
  310. Xgive the command 'p count=1000' and \fIgbench\fP will repeatedly draw
  311. X1000 polygons.  To get the feel of dragging around a 1000-polygon object,
  312. Xgive the command 'p d count=1000' and \fIgbench\fP will draw 1000 polygons
  313. Xevery time the mouse moves.  If you want exact control over the number
  314. Xof drawing operations executed for each command, set \fItimegoal\fP to 0
  315. Xand set \fIcount\fP as desired.
  316. X.TP
  317. Xangle
  318. XThe angle in degrees used for the 'arc' and 'vec' commands.
  319. X.TP
  320. Xaspect
  321. XA floating point value representing the height to width ratio of the
  322. Xbounding box for the 'arc' command.  The default value is 1.0, which
  323. Xyields circular arcs.
  324. X.TP
  325. Xfont
  326. XA comma-separated list of font names for \fIgbench\fP to load.
  327. XIn the X11 version, each name may contain the wild-card characters * and ?.
  328. XA maximum of 16 fonts may be loaded.
  329. X.TP
  330. Xptsize
  331. XThe font size, given in points, used in the 'text' command.
  332. X.TP
  333. Xlwidth
  334. XThe line width used in the drawing operations.
  335. X.TP
  336. Xmaxshift
  337. XEach drawing operation is shifted by one pixel in x and y from the previous
  338. Xoperation.  The shifting goes back and forth over a range of \fImaxshift\fP
  339. Xpixels.
  340. X.TP
  341. Xoffset
  342. XThe 'blit' command multiplies the size of the square being blitted by this
  343. Xfloating point value to determine how far to move it.  The default value
  344. Xis 0.5, which causes the destination square to overlap the source square.
  345. X.TP
  346. Xnchar
  347. XThe length in characters of the string drawn by the 'text' command.
  348. X.TP
  349. Xnwin
  350. XThe number of windows mapped by the 'map' command.
  351. X.TP
  352. Xnvert
  353. XThe number of vertices drawn by the 'poly' command.
  354. X.TP
  355. Xopts
  356. XThe option list that is prepended to the option list that is given as
  357. Xthe first positional parameter of a command.  It can be used to run scripts
  358. X(including the built-in script) with different lists of options.
  359. X.TP
  360. Xoutfile
  361. XThe name of the file that output is appended to (default:  standard output).
  362. X.TP
  363. Xsize
  364. XThe size in pixels of the objects drawn by the various drawing commands.
  365. X.TP
  366. Xtag
  367. XAn uninterpreted string that is included in the output of the 'config'
  368. Xcommand and at the beginning of each result line.  It is useful for
  369. Xassociating each result line with a named configuration when a log file is
  370. Xrun through \fIgbench\fP several times to accumulate result lines for
  371. Xdifferent configurations.  For example:
  372. X
  373. Xgbench -@d tag=configname <oldlog >newlog
  374. X
  375. XNote the use of the '@' on the 'defaults' command to prevent the tag-setting
  376. Xcommand from going into the log.  A suggested tag format is a quadruple of
  377. Xthe form
  378. X
  379. X<\fIrcpu\fP>.<\fIlcpu\fP>.<\fIwsys\fP>.<\fIgxsys\fP>
  380. X
  381. Xwhere \fIrcpu\fP is the type of the remote CPU running \fIgbench\fP (if any),
  382. X\fIlcpu\fP is the type of the local CPU running the window server, \fIwsys\fP
  383. Xis the name of the window system, and \fIgxsys\fP is the type of graphics
  384. Xhardware being used.  Each of these components can be encoded in two or three
  385. Xcharacters.
  386. X.TP
  387. Xwinsize
  388. XThe edge length (in pixels) of the square drawing window.
  389. X.SH VERSION
  390. XThis documentation applies to Version 1.0 of \fIgbench\fP.
  391. X.SH BUGS
  392. XThere is apparently a bug in the beta release of the awm window manager
  393. Xfor X11R2 that causes the "map" command to hang \fIgbench\fP.  For this
  394. Xreason, we have removed "map" from the default script.  We have not
  395. Xfound this problem under any of the other X11R2 window managers, including
  396. Xthe standard uwm.
  397. X.SH EXTENSIONS
  398. XDifferent drawable depths should be supported.  3D graphics and image
  399. Xprocessing operations should be supported when they become available.
  400. XFilters should be written to combine and format raw log files.
  401. X.SH AUTHOR
  402. X\fIgbench\fP is being developed by Craig Dunwoody and Mark Linton at Stanford
  403. XUniversity's Computer Systems Lab under the Quantum project, through a gift
  404. Xfrom Digital Equipment Corporation.
  405. X.SH ADDRESS
  406. XPlease send any comments, bugfixes, scripts, or results to:
  407. X
  408. XInternet: gbench@lurch.stanford.edu
  409. X
  410. XUSEnet:   {ucbvax,decvax}!decwrl!lurch.stanford.edu!gbench
  411. X
  412. X.SH COPYRIGHT
  413. X Copyright (c) 1988 by The Board of Trustees
  414. X of the Leland Stanford Junior University.
  415. X
  416. X Permission to use, copy, modify, and distribute this
  417. X software and its documentation for any purpose and without
  418. X fee is hereby granted, provided that the above copyright
  419. X notice appear in all copies and that both that copyright
  420. X notice and this permission notice appear in supporting
  421. X documentation, and that the name of Stanford not be used in
  422. X advertising or publicity pertaining to distribution of the
  423. X software without specific, written prior permission.
  424. X
  425. X Stanford makes no representations about the suitability of
  426. X this software for any purpose.  The Software is provided "as is"
  427. X without express or implied warranty.
  428. END_OF_FILE
  429. if test 17835 -ne `wc -c <'gbench.man'`; then
  430.     echo shar: \"'gbench.man'\" unpacked with wrong size!
  431. fi
  432. # end of 'gbench.man'
  433. fi
  434. if test -f 'ops.c' -a "${1}" != "-c" ; then 
  435.   echo shar: Will not clobber existing file \"'ops.c'\"
  436. else
  437. echo shar: Extracting \"'ops.c'\" \(10777 characters\)
  438. sed "s/^X//" >'ops.c' <<'END_OF_FILE'
  439. X#include <gbench.h>
  440. X
  441. Xvoid StartArc(sp,cp)
  442. X    State*  sp;
  443. X    Cmd*    cp;
  444. X{
  445. X    double  adjust;
  446. X    int        area = cp->p.size*cp->p.size;
  447. X    int        origin;
  448. X    double  theta;
  449. X
  450. X    cp->size[0] = sqrt(area/cp->p.aspect);
  451. X    cp->size[1] = sqrt(area*cp->p.aspect);
  452. X    if (cp->p.aspect!=1.) {
  453. X    theta = cp->p.angle*Pi/180;
  454. X    if (theta<(Pi/2)) adjust = 0.;
  455. X    else if (theta<(3*Pi/2)) adjust = Pi;
  456. X    else adjust = 2*Pi;
  457. X    theta = atan(tan(theta)/cp->p.aspect)+adjust;
  458. X    cp->size[2] = theta*180/Pi*64;
  459. X    }
  460. X    else cp->size[2] = cp->p.angle*64;
  461. X    origin = Border+cp->p.lwidth;
  462. X    cp->x = cp->y = Border;
  463. X    cp->bbx = cp->size[0]+2*cp->p.lwidth;
  464. X    cp->bby = cp->size[1]+2*cp->p.lwidth;
  465. X    if (cp->o.fill) {
  466. X    MoveClip(
  467. X        sp,cp,cp->x+cp->bbx/2-OverlapSize,cp->y+cp->bby/2-OverlapSize
  468. X    );
  469. X    }
  470. X    else MoveClip(sp,cp,cp->x,cp->y+cp->bby/2);
  471. X    Start(sp,cp);
  472. X}
  473. X
  474. Xvoid DoArc(sp,cp)
  475. X    State*  sp;
  476. X    Cmd*    cp;
  477. X{
  478. X    int i;
  479. X    int x = cp->x+cp->p.lwidth;
  480. X    int y = cp->y+cp->p.lwidth;
  481. X
  482. X    for (i=0;i<cp->p.count;i++) {
  483. X    StartIteration(sp,cp);
  484. X#    ifdef X11
  485. X        if (cp->o.fill) {
  486. X        XFillArc(
  487. X            sp->d,cp->dest,cp->gc,x,y,cp->size[0],cp->size[1],0,
  488. X            cp->size[2]
  489. X        );
  490. X        }
  491. X        else {
  492. X        XDrawArc(
  493. X            sp->d,cp->dest,cp->gc,x,y,cp->size[0],cp->size[1],0,
  494. X            cp->size[2]
  495. X        );
  496. X        }
  497. X#    endif X11
  498. X    }
  499. X}
  500. X
  501. Xvoid StartBlit(sp,cp)
  502. X    State*  sp;
  503. X    Cmd*    cp;
  504. X{
  505. X    Pixel   colorfg;
  506. X    int        i;
  507. X
  508. X    Start(sp,cp);
  509. X    cp->bbx = cp->bby = 0;
  510. X    colorfg = cp->colorfg;
  511. X    MoveClip(sp,cp,Border+cp->p.size/2,Border+cp->p.size/2);
  512. X    for (i=0;i<2;i++) {
  513. X    StartIteration(sp,cp);
  514. X#    ifdef X10
  515. X        XPixFill(
  516. X        cp->w,Border,Border,cp->p.size,cp->p.size,colorfg,0,cp->func,
  517. X        AllPlanes
  518. X        );
  519. X#    else
  520. X        XFillRectangle(
  521. X        sp->d,cp->src,sp->gc1,Border,Border,cp->p.size,cp->p.size
  522. X        );
  523. X#    endif
  524. X    }
  525. X    cp->x = cp->y = Border;
  526. X    cp->size[0] = cp->p.offset*cp->p.size;
  527. X}
  528. X
  529. Xvoid DoBlit(sp,cp)
  530. X    State*  sp;
  531. X    Cmd*    cp;
  532. X{
  533. X    XEvent            e;
  534. X    int                i;
  535. X    XGraphicsExposeEvent*   xep;
  536. X
  537. X#   ifdef X10
  538. X    xep = (XGraphicsExposeEvent*)&e;
  539. X#   else
  540. X    xep = &e.xgraphicsexpose;
  541. X#   endif
  542. X    for (i=0;i<cp->p.count;i++) {
  543. X    StartIteration(sp,cp);
  544. X#    ifdef X10
  545. X        XCopyArea(
  546. X        cp->w,Border,Border,cp->x+cp->size[0],cp->y+cp->size[0],
  547. X        cp->p.size,cp->p.size,cp->func,AllPlanes
  548. X        );
  549. X        if (cp->o.overlap) do {
  550. X        XMaskEvent(ExposeRegion|ExposureMask,&e);
  551. X        if (e.type==ExposeRegion) {
  552. X            XPixFill(
  553. X            cp->w,xep->x,xep->y,xep->width,xep->height,cp->colorfg,
  554. X            0,cp->func,AllPlanes
  555. X            );
  556. X        }
  557. X        } while (e.type!=ExposureMask);
  558. X#    else
  559. X        XCopyArea(
  560. X        sp->d,cp->src,cp->dest,cp->gc,Border,Border,cp->p.size,
  561. X        cp->p.size,cp->x+cp->size[0],cp->y+cp->size[0]
  562. X        );
  563. X        if (cp->o.overlap) do {
  564. X        XMaskEvent(sp->d,ExposureMask,&e);
  565. X        if (e.type==GraphicsExpose) {
  566. X            XFillRectangle(
  567. X            sp->d,cp->dest,cp->gc,xep->x,xep->y,xep->width,
  568. X            xep->height
  569. X            );
  570. X        }
  571. X        } while ((e.type==GraphicsExpose)&&xep->count);
  572. X#    endif
  573. X    }
  574. X}
  575. X
  576. Xvoid StartMap(sp,cp)
  577. X    State*  sp;
  578. X    Cmd*    cp;
  579. X{
  580. X    int        wheight;
  581. X    int        i;
  582. X    int        ncols = _DisplayWidth/cp->p.size;
  583. X#   ifdef X11
  584. X        XSetWindowAttributes swa;
  585. X#   endif X11
  586. X
  587. X    cp->x = cp->y = cp->bbx = cp->bby = 0;
  588. X    cp->p.nwin = Limit(cp->p.nwin,1,ncols*_DisplayHeight/cp->p.size);
  589. X    cp->o.altwin = false;
  590. X    wheight = cp->p.size*(1+cp->p.nwin/ncols);
  591. X    Start(sp,cp);
  592. X    UnmapWin(sp,cp->w);
  593. X    cp->w = XCreateSimpleWindow(
  594. X    DARGC _RootWindow,0,0,_DisplayWidth,wheight,1,WhitePixmap,BlackPixmap
  595. X    );
  596. X    for (i=0;i<cp->p.nwin;i++) {
  597. X    XCreateSimpleWindow(
  598. X        DARGC cp->w,cp->p.size*(i%ncols),cp->p.size*(i/ncols),cp->p.size,
  599. X        cp->p.size,1,WhitePixmap,BlackPixmap
  600. X    );
  601. X    }
  602. X#   ifdef X11
  603. X        swa.override_redirect = 1;
  604. X        XChangeWindowAttributes(sp->d,cp->w,CWOverrideRedirect,&swa);
  605. X#   endif X11
  606. X    XRaiseWindow(DARGC cp->w);
  607. X    XMapWindow(DARGC cp->w);
  608. X    XSelectInput(DARGC cp->w,InputMask(cp));
  609. X}
  610. X
  611. Xvoid DoMap(sp,cp)
  612. X    State*  sp;
  613. X    Cmd*    cp;
  614. X{
  615. X    int i;
  616. X
  617. X    for (i=0;i<cp->p.count;i++) {
  618. X    XMapSubwindows(DARGC cp->w);
  619. X    XUnmapSubwindows(DARGC cp->w);
  620. X    }
  621. X}
  622. X
  623. Xvoid FinishMap(sp,cp)
  624. X    State*  sp;
  625. X    Cmd*    cp;
  626. X{
  627. X    Finish(sp,cp);
  628. X    XUnmapWindow(DARGC cp->w);
  629. X    XDestroyWindow(DARGC cp->w);
  630. X    cp->w = sp->w1;
  631. X    MapWin(sp,cp->w);
  632. X    XFlush(DARG);
  633. X}
  634. X
  635. Xvoid DoNop(sp,cp)
  636. X    State*  sp;
  637. X    Cmd*    cp;
  638. X{
  639. X    int    i;
  640. X
  641. X#   ifdef X11
  642. X    for (i=0;i<cp->p.count;i++) XNoOp(sp->d);
  643. X#   endif X11
  644. X}
  645. X
  646. Xvoid StartPoint(sp,cp)
  647. X    State*  sp;
  648. X    Cmd*    cp;
  649. X{
  650. X    cp->x = cp->y = Border;
  651. X    cp->bbx = cp->bby = 1;
  652. X    MoveClip(sp,cp,cp->x,cp->y);
  653. X    Start(sp,cp);
  654. X}
  655. X
  656. Xvoid DoPoint(sp,cp)
  657. X    State*  sp;
  658. X    Cmd*    cp;
  659. X{
  660. X    int i;
  661. X    
  662. X#   ifdef X11
  663. X    for (i=0;i<cp->p.count;i++) {
  664. X        StartIteration(sp,cp);
  665. X        XDrawPoint(sp->d,cp->dest,cp->gc,cp->x,cp->y);
  666. X    }
  667. X#   endif
  668. X}
  669. X
  670. Xvoid StartPoly(sp,cp)
  671. X    State*  sp;
  672. X    Cmd*    cp;
  673. X{
  674. X    int        fillrule;
  675. X    int        i;
  676. X    int        index;
  677. X    int        origin = Border+cp->p.lwidth;
  678. X    int        r = cp->p.size/2;
  679. X    double  theta;
  680. X
  681. X    if (cp->o.polyself) cp->p.nvert = cp->p.nvert/2*2+1;
  682. X    theta = 2*Pi/cp->p.nvert;
  683. X    cp->x = cp->y = Border;
  684. X    cp->bbx = cp->bby = cp->p.size+2*cp->p.lwidth;
  685. X    for (i=0;i<=cp->p.nvert;i++) {
  686. X    index = cp->o.polyself?(i*(cp->p.nvert/2))%cp->p.nvert:i;
  687. X    sp->v[i].x = origin+r*(1+cos(PolyAngle+index*theta));
  688. X    sp->v[i].y = origin+r*(1-sin(PolyAngle+index*theta));
  689. X    }
  690. X#   ifdef X10
  691. X    sp->v[0].flags = VertexStartClosed;
  692. X    for (i=1;i<cp->p.nvert;i++) sp->v[i].flags = 0;
  693. X    sp->v[cp->p.nvert].flags = VertexEndClosed;
  694. X#   else
  695. X    fillrule = cp->o.polywind?WindingRule:EvenOddRule;
  696. X    XSetFillRule(sp->d,sp->gc1,fillrule);
  697. X    XSetFillRule(sp->d,sp->gc2,fillrule);
  698. X#   endif
  699. X    if (cp->o.fill) MoveClip(sp,cp,cp->x+r,cp->x+r);
  700. X    else MoveClip(sp,cp,sp->v[0].x,sp->v[0].y);
  701. X    Start(sp,cp);
  702. X}
  703. X
  704. Xvoid DoPoly(sp,cp)
  705. X    State*  sp;
  706. X    Cmd*    cp;
  707. X{
  708. X    int i;
  709. X#   ifdef X11
  710. X    int shape = cp->o.polyself?Complex:Convex;
  711. X#   endif X11
  712. X
  713. X    MoveVert(sp,cp,cp->p.nvert);
  714. X    for (i=0;i<cp->p.count;i++) {
  715. X    StartIteration(sp,cp);
  716. X#    ifdef X10
  717. X        X10Draw(sp,cp,cp->p.nvert+1);
  718. X#    else
  719. X        if (cp->o.fill) {
  720. X        XFillPolygon(
  721. X            sp->d,cp->dest,cp->gc,sp->v,cp->p.nvert,shape,
  722. X            CoordModeOrigin
  723. X        );
  724. X        }
  725. X        else {
  726. X        XDrawLines(
  727. X            sp->d,cp->dest,cp->gc,sp->v,cp->p.nvert+1,CoordModeOrigin
  728. X        );
  729. X        }
  730. X#    endif
  731. X    }
  732. X}
  733. X
  734. Xvoid StartRect(sp,cp)
  735. X    State*  sp;
  736. X    Cmd*    cp;
  737. X{
  738. X    int i;
  739. X    int origin = Border+cp->p.lwidth;
  740. X
  741. X    cp->x = cp->y = Border;
  742. X    cp->bbx = cp->bby = cp->p.size+2*cp->p.lwidth;
  743. X#   ifdef X10
  744. X    for (i=0;i<5;i++) {
  745. X        sp->v[i].x = origin;
  746. X        sp->v[i].y = origin;
  747. X    }
  748. X    sp->v[1].x += cp->p.size;
  749. X    sp->v[2].x += cp->p.size;
  750. X    sp->v[2].y += cp->p.size;
  751. X    sp->v[3].y += cp->p.size;
  752. X    sp->v[0].flags = VertexStartClosed;
  753. X    for (i=1;i<4;i++) sp->v[i].flags = 0;
  754. X    sp->v[4].flags = VertexEndClosed;
  755. X#   endif X10
  756. X    if (cp->o.fill) MoveClip(sp,cp,cp->x+cp->bbx/2,cp->y+cp->bby/2);
  757. X    else MoveClip(sp,cp,cp->x,cp->y);
  758. X    Start(sp,cp);
  759. X}
  760. X
  761. Xvoid DoRect(sp,cp)
  762. X    State*  sp;
  763. X    Cmd*    cp;
  764. X{
  765. X    int    i;
  766. X    int x = cp->x+cp->p.lwidth;
  767. X    int y = cp->y+cp->p.lwidth;
  768. X
  769. X#   ifdef X10
  770. X    if (!cp->o.fill) MoveVert(sp,cp,5);
  771. X#   endif X10
  772. X    for (i=0;i<cp->p.count;i++) {
  773. X    StartIteration(sp,cp);
  774. X#    ifdef X10
  775. X        if (cp->o.fill) {
  776. X        if (cp->o.tile) {
  777. X            XTileFill(
  778. X            cp->w,x,y,cp->p.size,cp->p.size,sp->tile,0,cp->func,
  779. X            AllPlanes
  780. X            );
  781. X        }
  782. X        else {
  783. X            XPixFill(
  784. X            cp->w,x,y,cp->p.size,cp->p.size,cp->colorfg,0,cp->func,
  785. X            AllPlanes
  786. X            );
  787. X        }
  788. X        }
  789. X        else X10Draw(sp,cp,5);
  790. X#    else
  791. X        if (cp->o.fill) {
  792. X        XFillRectangle(
  793. X            sp->d,cp->dest,cp->gc,x,y,cp->p.size,cp->p.size
  794. X        );
  795. X        }
  796. X        else {
  797. X        XDrawRectangle(
  798. X            sp->d,cp->dest,cp->gc,x,y,cp->p.size,cp->p.size
  799. X        );
  800. X        }
  801. X#    endif
  802. X    }
  803. X}
  804. X
  805. Xvoid StartText(sp,cp)
  806. X    State*  sp;
  807. X    Cmd*    cp;
  808. X{
  809. X    int findex = FontIndex(sp,&cp->p.ptsize);
  810. X    int    i;
  811. X
  812. X    cp->x = cp->y = Border;
  813. X    Start(sp,cp);
  814. X    if (findex<0) {
  815. X    cp->p.ptsize = 0;
  816. X    cp->fontid = nil;
  817. X    cp->bbx = cp->bby = 0;
  818. X    cp->result = NoFonts;
  819. X    }
  820. X    else {
  821. X#    ifdef X10
  822. X        cp->p.ptsize = sp->fontinfo[findex]->height;
  823. X        cp->fontid = sp->fontinfo[findex]->id;
  824. X        cp->bbx = cp->p.nchar*sp->fontinfo[findex]->width;
  825. X        cp->bby = sp->fontinfo[findex]->height;
  826. X#    else
  827. X        cp->p.ptsize = sp->fontinfo[findex]->ascent;
  828. X        XSetFont(sp->d,sp->gc1,sp->fontinfo[findex]->fid);
  829. X        XSetFont(sp->d,sp->gc2,sp->fontinfo[findex]->fid);
  830. X        cp->fontid = sp->fontinfo[findex]->fid;
  831. X        cp->size[0] = sp->fontinfo[findex]->max_bounds.ascent;
  832. X        cp->bbx = cp->p.nchar*sp->fontinfo[findex]->max_bounds.width;
  833. X        cp->bby = cp->size[0]+sp->fontinfo[findex]->max_bounds.descent;
  834. X        if (cp->o.altfont) for (i=0;i<cp->p.nchar;i++) {
  835. X        sp->texts[i].font = cp->fontid;
  836. X        }
  837. X#    endif
  838. X    }
  839. X    MoveClip(sp,cp,cp->x+cp->bbx/2,cp->y+cp->bby/2);
  840. X}
  841. X
  842. Xvoid DoText(sp,cp)
  843. X    State*  sp;
  844. X    Cmd*    cp;
  845. X{
  846. X    int    i;
  847. X
  848. X    if (cp->result==NoFonts) return;
  849. X    for (i=0;i<cp->p.count;i++) {
  850. X    StartIteration(sp,cp);
  851. X#    ifdef X10
  852. X        if (cp->o.tile) {
  853. X        XTextPad(
  854. X            cp->w,cp->x,cp->y,sp->outstr,cp->p.nchar,cp->fontid,0,0,
  855. X            cp->colorfg,cp->colorbg,cp->func,AllPlanes
  856. X        );
  857. X        }
  858. X        else {
  859. X        XTextMaskPad(
  860. X            cp->w,cp->x,cp->y,sp->outstr,cp->p.nchar,cp->fontid,0,0,
  861. X            cp->colorfg,cp->func,AllPlanes
  862. X        );
  863. X        }
  864. X#    else
  865. X        if (cp->o.altfont) {
  866. X        XDrawText(
  867. X            sp->d,cp->dest,cp->gc,cp->x,cp->y+cp->size[0],sp->texts,
  868. X            cp->p.nchar
  869. X        );
  870. X        }
  871. X        else if (cp->o.tile) {
  872. X        XDrawImageString(
  873. X            sp->d,cp->dest,cp->gc,cp->x,cp->y+cp->size[0],sp->outstr,
  874. X            cp->p.nchar
  875. X        );
  876. X        }
  877. X        else {
  878. X        XDrawString(
  879. X            sp->d,cp->dest,cp->gc,cp->x,cp->y+cp->size[0],sp->outstr,
  880. X            cp->p.nchar
  881. X        );
  882. X        }
  883. X#    endif
  884. X    }
  885. X}
  886. X
  887. Xvoid StartVec(sp,cp)
  888. X    State*  sp;
  889. X    Cmd*    cp;
  890. X{
  891. X    double  theta = cp->p.angle*Pi/180;
  892. X    int        xoffset = cp->p.lwidth*Sign(cos(theta));
  893. X    int        yoffset = cp->p.lwidth*Sign(-sin(theta));
  894. X    int        xorigin = sp->winsize/2;
  895. X    int        yorigin = sp->winsize/2;
  896. X
  897. X#   ifdef X10
  898. X    sp->v[0].flags = 0;
  899. X    sp->v[1].flags = 0;
  900. X#   endif X10
  901. X    cp->x = xorigin;
  902. X    cp->y = yorigin;
  903. X    xorigin += xoffset;
  904. X    yorigin += yoffset;
  905. X    cp->bbx = cp->p.size*cos(theta);
  906. X    cp->bby = cp->p.size*-sin(theta);
  907. X    sp->v[0].x = xorigin;
  908. X    sp->v[0].y = yorigin;
  909. X    sp->v[1].x = xorigin+cp->bbx;
  910. X    sp->v[1].y = yorigin+cp->bby;
  911. X    cp->bbx += 2*xoffset;
  912. X    cp->bby += 2*yoffset;
  913. X    cp->o.fill = false;
  914. X    MoveClip(sp,cp,cp->x+cp->bbx/2,cp->y+cp->bby/2);
  915. X    Start(sp,cp);
  916. X}
  917. X
  918. Xvoid DoVec(sp,cp)
  919. X    State*  sp;
  920. X    Cmd*    cp;
  921. X{
  922. X    int i;
  923. X
  924. X    MoveVert(sp,cp,2);
  925. X    for (i=0;i<cp->p.count;i++) {
  926. X    StartIteration(sp,cp);
  927. X#    ifdef X10
  928. X        X10Draw(sp,cp,2);
  929. X#    else
  930. X        XDrawLine(
  931. X        sp->d,cp->dest,cp->gc,sp->v[0].x,sp->v[0].y,sp->v[1].x,
  932. X        sp->v[1].y
  933. X        );
  934. X#    endif
  935. X    }
  936. X}
  937. END_OF_FILE
  938. if test 10777 -ne `wc -c <'ops.c'`; then
  939.     echo shar: \"'ops.c'\" unpacked with wrong size!
  940. fi
  941. # end of 'ops.c'
  942. fi
  943. echo shar: End of archive 2 \(of 2\).
  944. cp /dev/null ark2isdone
  945. MISSING=""
  946. for I in 1 2 ; do
  947.     if test ! -f ark${I}isdone ; then
  948.     MISSING="${MISSING} ${I}"
  949.     fi
  950. done
  951. if test "${MISSING}" = "" ; then
  952.     echo You have unpacked both archives.
  953.     rm -f ark[1-9]isdone
  954. else
  955.     echo You still need to unpack the following archives:
  956.     echo "        " ${MISSING}
  957. fi
  958. ##  End of shell archive.
  959. exit 0
  960.